<!-- src/components/loadingBar/TopLoading.vue -->
<script setup lang="ts">
import { useLoadingBar } from 'naive-ui'
import { onMounted } from 'vue'
import { useRouter } from 'vue-router'

const loadingBar = useLoadingBar()
const router = useRouter()

// 设置路由守卫
onMounted(() => {
  router.beforeEach((to, from, next) => {
    loadingBar.start()
    next()
  })

  router.afterEach(() => {
    loadingBar.finish()
  })

  router.onError(() => {
    loadingBar.error()
  })
})
</script>
